//
//  MLAManageAdvertCell.m
//  MagicLampApp
//
//  Created by Zheng on 2018/12/20.
//  Copyright © 2018 zheng.magic.lamp.app. All rights reserved.
//

#import "MLAManageAdvertCell.h"
#import "MLAManageAdvertModel.h"

@implementation MLAManageAdvertCell {
    UILabel *titleLbl;
    UILabel *nameLbl;
    UILabel *mobileLbl;
    UILabel *addressLbl;
    UILabel *moneyLbl;
    UILabel *typeLbl;
}

- (void)setModel:(MLAManageAdvertModel *)model {
    _model = model;
    
    NSString *priceStr = [NSString stringWithFormat:@"%@/天",_model.price];
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:priceStr];
    [attrStr addAttribute:NSForegroundColorAttributeName value:CX_GetColorHex(0x6B7178, 1) range:NSMakeRange(attrStr.length-2, 2)];
    [attrStr addAttribute:NSFontAttributeName value:CX_GetNormalFont(12) range:NSMakeRange(attrStr.length-2, 2)];
    moneyLbl.attributedText = attrStr;
    
    addressLbl.text = [NSString stringWithFormat:@"位置：%@",_model.position_name];
    mobileLbl.text = [NSString stringWithFormat:@"电话：%@",_model.tel];
    nameLbl.text = [NSString stringWithFormat:@"联系人：%@",_model.contacts];
    titleLbl.text = _model.cname;
    
    if(_model.status.integerValue == 1) {
        typeLbl.hidden = YES;
        _applyBtn.hidden = NO;
    } else {
        typeLbl.hidden = NO;
        _applyBtn.hidden = YES;
    }
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        titleLbl = [[UILabel alloc] init];
        titleLbl.font = CX_GetNormalFont(16);
        titleLbl.textColor = CX_GetColorTitle();
        [self.shadowView addSubview:titleLbl];
        [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.top.mas_equalTo(19);
        }];
        
        nameLbl = [[UILabel alloc] init];
        nameLbl.font = CX_GetNormalFont(12);
        nameLbl.textColor = CX_GetColorTitle();
        [self.shadowView addSubview:nameLbl];
        [nameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.top.equalTo(self->titleLbl.mas_bottom).offset(18);
        }];
        
        mobileLbl = [[UILabel alloc] init];
        mobileLbl.font = CX_GetNormalFont(12);
        mobileLbl.textColor = CX_GetColorTitle();
        [self.shadowView addSubview:mobileLbl];
        [mobileLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.top.equalTo(self->nameLbl.mas_bottom).offset(9);
        }];
        
        addressLbl = [[UILabel alloc] init];
        addressLbl.font = CX_GetNormalFont(12);
        addressLbl.textColor = CX_GetColorTitle();
        [self.shadowView addSubview:addressLbl];
        [addressLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.top.equalTo(self->mobileLbl.mas_bottom).offset(9);
        }];
        
        moneyLbl = [[UILabel alloc] init];
        moneyLbl.font = CX_GetNormalFont(16);
        moneyLbl.textColor = CX_GetColorRed();
        [self.shadowView addSubview:moneyLbl];
        [moneyLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-15);
            make.centerY.equalTo(self->titleLbl);
        }];
        
        typeLbl = [[UILabel alloc] init];
        typeLbl.font = CX_GetNormalFont(14);
        typeLbl.textColor = CX_GetColorHex(0x6B7178, 1);
        typeLbl.text = @"已申请";
        typeLbl.hidden = YES;
        [self.shadowView addSubview:typeLbl];
        [typeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-15);
            make.bottom.mas_equalTo(-29);
        }];
        
        _applyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_applyBtn setTitle:@"申请租用" forState:UIControlStateNormal];
        [_applyBtn setTitleColor:CX_GetColorBlue() forState:UIControlStateNormal];
        _applyBtn.titleLabel.font = CX_GetNormalFont(14);
        _applyBtn.layer.borderColor = CX_GetColorBlue().CGColor;
        _applyBtn.layer.borderWidth = 1;
        _applyBtn.layer.cornerRadius = 5;
        _applyBtn.layer.masksToBounds = YES;
        _applyBtn.hidden = YES;
        [self.shadowView addSubview:_applyBtn];
        [_applyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-15);
            make.bottom.mas_equalTo(-21);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(30);
        }];
        
        /*
        测试数据
        NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:@"2000/天"];
        [attrStr addAttribute:NSForegroundColorAttributeName value:CX_GetColorHex(0x6B7178, 1) range:NSMakeRange(attrStr.length-2, 2)];
        [attrStr addAttribute:NSFontAttributeName value:CX_GetNormalFont(12) range:NSMakeRange(attrStr.length-2, 2)];
        moneyLbl.attributedText = attrStr;
        addressLbl.text = @"位置：A区外侧3层";
        mobileLbl.text = @"电话：135154258466";
        nameLbl.text = @"联系人：张三";
        titleLbl.text = @"外墙广告";
         if (arc4random()%2 == 0) {
         typeLbl.hidden = NO;
         _applyBtn.hidden = YES;
         } else {
         typeLbl.hidden = YES;
         _applyBtn.hidden = NO;
         }
        */
        

    }
    return self;
}


@end
